package com.example.liyuehui.myapplication;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;


public class NestedPagerAdapter extends PagerAdapter {

	//当前recyclerview位置
	private int currentRecyclerViewPosition;

	public void setCurrentRecyclerViewPosition(int currentRecyclerViewPosition) {
		this.currentRecyclerViewPosition = currentRecyclerViewPosition;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return 2;
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		if (currentRecyclerViewPosition == 0) {
			ImageView tv = new ImageView(container.getContext());
			if (position == 0) {
				tv.setBackgroundResource(R.mipmap.wu);
			} else {
				tv.setBackgroundResource(R.mipmap.wu2);
			}
			container.addView(tv);
			return tv;
		} else {
			ImageView tv = new ImageView(container.getContext());
			if (position == 0) {
				tv.setBackgroundResource(R.mipmap.lin);
			} else {
				tv.setBackgroundResource(R.mipmap.lin2);
			}
			container.addView(tv);
			return tv;
		}
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
	}
}
